/**
 * 用户信息新增页面JS
 * User: zhaoming
 * Date: 15-8-17
 * Time: 下午5:58
 * To change this template use File | Settings | File Templates.
 */
$(function(){
    //激活左侧导航菜单
    activeNavBar("AUTHORITY_USER_INFO", "AUTHORITY");
    $('#addForm')[0].reset();

    $("#save").click(function(){
        save();
    });

    $("#goBack").click(function(){
        window.location.href = "/web/userInfo/index";
    });

    $('#file').ace_file_input({
        style:'well',
        btn_choose:'Change Picture',
        btn_change:null,
        no_icon:'ace-icon fa fa-picture-o',
        thumbnail:'large',
        droppable:true,
        allowExt: ['jpg', 'jpeg', 'png', 'gif'],
        allowMime: ['image/jpg', 'image/jpeg', 'image/png', 'image/gif']
    }).on('change', function(){
        //console.log($(this).data('ace_input_files'));
        //console.log($(this).data('ace_input_method'));
    });
    //$('#file').ace_file_input('show_file_list', [{type: 'image', name: "/static/avatars/profile-pic.jpg"}]);
});

/**
 * 保存
 */
function save(){

    if($('#addForm').trigger("validate").isValid()){
        Loading.show();
        var formData = new FormData();//构造空对象，下面用append 方法赋值。
        formData.append("file", $("#file")[0].files[0]);
        formData.append("userCode", $('#userCode').val());
        formData.append("userName", $('#userName').val());
        formData.append("passWord", $('#passWord').val());
        formData.append("isPhoneAlert", $("#isPhoneAlert").attr("checked") ? 1 : 0);
        formData.append("phone", $('#phone').val());
        formData.append("isEmailAlert", $("#isEmailAlert").attr("checked") ? 1 : 0);
        formData.append("email", $('#email').val());
        jQuery.ajax({
            type: "POST",
            url: springUrl+"/web/userInfo/insert",
            data: formData,
            processData : false,
            contentType : false,
            success:function (data) {
                Loading.hide();
                Commons.showSuccess("数据保存成功!", function(){
                    window.location.href = springUrl+"/web/userInfo/index";
                });
            },
            error : function(data){
                Loading.hide();
                Commons.showError("数据保存失败!");
            }
        });
    }
}

